package com.itheima;

/**
 * 2025/3/22 9:25
 * 演示自增自减运算符的使用
 */
public class OperationDemo2 {

    public static void main(String[] args) {

        int a = 10;
        a++;
        System.out.println(a);//11
        ++a;//
        System.out.println(a);//12

        int b = 10;
        b--;
        System.out.println(b);//9
        --b;
        System.out.println(b);//8

        //只能作用在变量上，不能作用在常量上（字面量）

//        System.out.println(10++);//不支持

        System.out.println("-----------------------");

        int c = 10;
        int rs = c++;
        System.out.println("c = " + c);//11
        System.out.println("rs = " + rs);//10

        int d = 10;
        int rs2 = ++d;
        System.out.println("d = " + d);//11
        System.out.println("rs2 = " + rs2);//11
        System.out.println("--------------------");
        //调用方法
        test1();
        System.out.println("---------------------");
        //调用方法
        test2();
    }

    public static void test1() {
        int c = 10;
        int d = 5;
        int rs3 = c++ + ++d;
        System.out.println("c = " + c);//11
        System.out.println("d = " + d);//6
        System.out.println("rs3 = " + rs3);//16
    }

    public static void test2() {
        int c = 10;
        int d = 5;
        int rs3 = c++ + ++c - --d - ++d + 1 + c--;
        System.out.println("c = " + c);//
        System.out.println("d = " + d);//
        System.out.println("rs3 = " + rs3);//
    }


}
